﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Kinect;

namespace ISMOT.HCI.KGL
{
    public class Gesture
    {
        public Gesture()
        {
            this.Poses = new List<Pose>();
        }

        private List<Pose> Poses { get; set; }
        private int PoseToHitIndex { get; set; }
        private Pose LastPose { get; set; }

        public void AddPose(Pose pose)
        {
            this.Poses.Add(pose);
        }

        public bool IsHit(Skeleton body)
        {
            Pose poseToHit = this.Poses[this.PoseToHitIndex];

            if (this.IsInRightDirection(body, this.LastPose, poseToHit))
            {
                if (poseToHit.IsHit(body))
                {
                    this.PoseToHitIndex++;
                    this.LastPose = poseToHit;
                }
                if (this.PoseToHitIndex == this.Poses.Count)
                {
                    this.Reset();
                    return (true);
                }
            }
            else
                this.Reset();

            return (false);
        }

        private void Reset()
        {
            this.LastPose = null;
            this.PoseToHitIndex = 0;
        }

        private bool IsInRightDirection(Skeleton body, Pose lastPose, Pose poseToHit)
        {
            if (lastPose == null)
                return (true);

            return (false);
        }
    }
}
